<script setup>
import { ArrowLeftIcon } from 'tdesign-icons-vue-next'
import { ref } from 'vue'
import TableBase from '@/components/Table-Base.vue'
import { getMonthlyCardList } from '@/api/monthly'
import { useRoute, useRouter } from 'vue-router'
import MainContent from '@/components/Main-Content.vue'

const router = useRouter()
const route = useRoute()
const infoData = ref({})
const listData = ref([])
const columns = ref([
    {
        title: '序号',
        colKey: 'serial-number',
        width: 80
    },
    {
        title: '有效日期',
        colKey: 'date',
        width: 250
    },
    {
        title: '支付金额',
        colKey: 'paymentAmount'
    },
    {
        title: '支付方式',
        colKey: 'paymentMethod'
    },
    {
        title: '办理时间',
        colKey: 'createTime',
        width: 220
    },
    {
        title: '办理人',
        colKey: 'createUser'
    }
])

const back = () => router.back()
const getList = async () => {
    const res = await getMonthlyCardList(route.query.id)
    infoData.value = res.data
    listData.value = res.data.rechargeList.map(e => {
        e.date = e.cardStartDate + '至' + e.cardEndDate
        return e
    })
}

getList()
</script>

<template>
    <main-content>
        <div class="header">
            <t-button variant="outline" @click="back">
                <template #icon>
                    <ArrowLeftIcon/>
                </template>
                返回
            </t-button>
            <span class="title">月卡详情记录</span>
        </div>

        <t-divider theme="vertical"/>

        <div class="body">
            <t-card title="车辆信息" header-bordered>
                <div class="info">
                    <div class="item">
                        <span>车主姓名：</span>
                        <span>{{ infoData.personName }}</span>
                    </div>
                    <div class="item">
                        <span>联系方式：</span>
                        <span>{{ infoData.phoneNumber }}</span>
                    </div>
                    <div class="item">
                        <span>车牌号码：</span>
                        <span>{{ infoData.carNumber }}</span>
                    </div>
                    <div class="item">
                        <span>车辆品牌：</span>
                        <span>{{ infoData.carBrand }}</span>
                    </div>
                </div>
            </t-card>

            <t-card title="月卡缴费记录" header-bordered class="table-card">
                <table-base :columns="columns" :list="listData"/>
            </t-card>
        </div>
    </main-content>
</template>

<style scoped lang="scss">
.header {
    display: flex;
    align-items: center;
    padding: 20px 20px 0;

    .title {
        color: var(--td-text-color-primary);
        font-size: 24px;
        font-weight: 600;
        margin-left: 30px;
    }
}

.body {
    padding: 10px 30px;

    .t-card {
        width: 100%;

        .info {
            display: flex;
            flex-wrap: wrap;

            .item {
                width: 50%;
                min-width: 200px;
                min-height: 40px;
                display: flex;
                align-items: center;

                span:first-child {
                    color: var(--td-text-color-secondary);
                }

                span:last-child {
                    font-weight: 500;
                }
            }
        }

        .table {
            padding: 0;

            :deep .t-table {
                border-radius: 0 0 var(--td-radius-medium) var(--td-radius-medium);

                .t-table__content {
                    border-radius: 0 0 var(--td-radius-medium) var(--td-radius-medium);

                    .t-table__body {
                        tr:last-of-type {
                            td {
                                border-bottom: 0;
                            }
                        }
                    }
                }
            }
        }

        &:first-of-type {
            margin-bottom: 20px;
        }
    }

    :deep .table-card {
        .t-card__body {
            padding: 0;
        }
    }
}

.t-divider {
    margin: 20px 0;
}
</style>
